package fr.esiag.isidis.fi.Team.Parcer;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.Date;

public class ReceiveRawInformation {

	private MessageBoard mb;
	
	public ReceiveRawInformation() {
		mb=new MessageBoard();
		receive();
	}
	Date now=new Date();
	
	void receive(){
		
		try{
		 DatagramSocket serverSocket = new DatagramSocket(12345);
         byte[] receiveData = new byte[2];
         RawInformationParcer parcer=new RawInformationParcer();
         System.out.println("en attente de connection...");
            while(true)
            {
               DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
               serverSocket.receive(receivePacket);
               byte b1=receiveData[0];
				byte b2=receiveData[1];
				parcer.Parce(b1, b2);
				Date now =new Date();
				mb.AddMessage(now.toGMTString()+" => "+parcer.getParcedInformation());
            }
		}catch(Exception ex){
			System.out.println();
		}
	}
	
	public static void main(String[] args) {
		new ReceiveRawInformation();
	}
}